package com.deng.maintenance.employee.view
{
	import com.deng.common.vo.AdminDepartmentVo;
	import com.deng.maintenance.model.MaintenanceModelLocator;
	
	import flash.events.MouseEvent;
	
	import mx.controls.Alert;
	import mx.controls.CheckBox;
	import mx.events.FlexEvent;
	import mx.resources.ResourceManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	public class GuanLiKeShiSelCB extends CheckBox
	{
		private var selVo:AdminDepartmentVo;
		public function GuanLiKeShiSelCB()
		{
			this.addEventListener(FlexEvent.CREATION_COMPLETE,showHandler);
			this.addEventListener(MouseEvent.MOUSE_UP,upEvt);
			this.addEventListener(FlexEvent.SHOW,showHandler);
			super();
		}
		private function upEvt(event:MouseEvent):void{			
//			var ro:RemoteObject = new RemoteObject();
//			ro.destination = "EmployeeImpl";			
//			ro.addEventListener(FaultEvent.FAULT,flt);
//			ro.addEventListener(ResultEvent.RESULT,updateRst);
									
			if(this.selected){//之前选中的，后面要删除
				if(selVo.zhuguan == 1){//主管科室
					MaintenanceModelLocator.getInstance().empZhuGuanKeShi.replace(":"+selVo.id+":","");
//				ro.setEmployeeGuanlikeshi(selVo,selVo.zhuguan,selVo.id,0);					
				}else{//分管科室
					MaintenanceModelLocator.getInstance().empFenGuanKeShi.replace(":"+selVo.id+":","");
				}				
				selVo.selected = 0;
			}else{//之前没选中，后面要增加
				if(selVo.zhuguan == 1){//主管科室
					MaintenanceModelLocator.getInstance().empZhuGuanKeShi = MaintenanceModelLocator.getInstance().empZhuGuanKeShi+":"+selVo.id+":";
				}else{//分管科室
					MaintenanceModelLocator.getInstance().empFenGuanKeShi = MaintenanceModelLocator.getInstance().empFenGuanKeShi+":"+selVo.id+":";
				}
//				ro.setEmployeeGuanlikeshi(selVo,selVo.zhuguan,selVo.id,1);
				selVo.selected = 1;	
			}			
		}
		private function updateRst(evt:ResultEvent):void{
			Alert.show(ResourceManager.getInstance().getString("lang", "update_success"));
		}
		private function flt(evt:FaultEvent):void{
			Alert.show(evt.fault.getStackTrace());
		}
		private function showHandler(evt:FlexEvent):void{
			selVo = this.data as AdminDepartmentVo;
			if(selVo.selected == 1){
				this.selected = true;
			}else{
				this.selected = false;
			}			
		}
		
	}
}